package com.tech.java;

import com.sun.org.apache.xpath.internal.SourceTree;
import org.junit.Test;

import javax.swing.*;
import java.util.*;

/**
 * @Description:
 * @Author: zl
 * @Date: 2019/7/10 11:00
 */
public class Set {

    // Dummy value to associate with an Object in the backing Map
    private static final Object PRESENT = new Object();

    @Test
    // 1 无序 2 底层采用hashMap 的可以进行数据存储 3、不可重复
    public  void hashSet(){
        HashSet<String> set = new HashSet<>();
        set.add("string1");
        set.add("string2");
        set.add("string3");
        set.add("string4");
        set.add("string5");
        set.add("string5");
        Iterator<String> iter = set.iterator();
        while (iter.hasNext()) {
            String string = iter.next();
            System.out.println("string--"+string);
        }

        //set.forEach(item-> System.out.println(item));
    }

    @Test
    // 有序 treeMap数据结构
    public void treeSet(){
        TreeSet set  = new TreeSet();
        set.add("string1");
        set.add("string2");
        set.add("string3");
        set.add("string4");
        set.add("string5");

        set.forEach(item-> System.out.println(item));
    }

    public static void main(String[] args) {
        HashMap<String,Object> map = new HashMap();
        map.put("a",PRESENT);
        map.put("b",PRESENT);
        map.put("c",PRESENT);
        for (Map.Entry<String,Object> entry: map.entrySet()) {
            System.out.println(entry.getKey()+"----"+entry.getValue());
        }
    }
}
